package com.example.controller;

import com.example.common.Result;
import com.example.entity.Account;
import com.example.entity.Course;
import com.example.entity.Student;
import com.example.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/studentIfo")
public class StudentController {
    @Resource
    StudentService studentService;
    @PostMapping("/add")
    public Result add(@RequestBody Student student){
        studentService.insert(student);
        return Result.success();
    }
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Student student){
        PageInfo<Student> pageInfo=studentService.selectPage(pageNum,pageSize,student);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectSingle/{username}")
    public Result selectSingel(@PathVariable String username){
        Account student = studentService.selectSingle(username);
        return Result.success(student);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Student student){
        studentService.updateById(student);
        return Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        studentService.deleteById(id);
        return Result.success();
    }
}
